package com.mengjiahui.auduoplayer.activity;

import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.mengjiahui.auduoplayer.adapter.PlayListAdapter;
import com.mengjiahui.auduoplayer.R;
import com.mengjiahui.auduoplayer.bean.Music;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Meng
 * @data 2020/5/9
 */
public class PlayListActivity extends AppCompatActivity {
    private Toolbar toolbar;
    private RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play_list);
        toolbar = findViewById(R.id.toolbar_play_list);
        toolbar.setTitle("播放列表");
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        recyclerView = findViewById(R.id.recyclerViewPlayList);
        List<Music> musicList = new ArrayList<>();
        musicList.add(new Music(R.mipmap.ic_music, "桥边姑娘", "舞蹈女神诺诺-桥边姑娘"));
        PlayListAdapter playListAdapter = new PlayListAdapter(PlayListActivity.this, R.layout.item_play_list, musicList);
        recyclerView.setAdapter(playListAdapter);
        playListAdapter.setListener(position -> {
                    Intent intent = new Intent(PlayListActivity.this, PlayMusicActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putSerializable("music",musicList.get(position));
                    intent.putExtras(bundle);
                    startActivity(intent);
                }
        );
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(PlayListActivity.this);
        recyclerView.setLayoutManager(linearLayoutManager);
    }
}
